import 'package:boss/provider/login_user_provider.dart';
import 'package:boss/ui/widget/button/fixed_bottom_btn.dart';
import 'package:boss/ui/widget/center_title_app_bar.dart';
import 'package:boss/ui/widget/custom_divier.dart';
import 'package:boss/ui/widget/loginRegistForget/lrf_title.dart';
import 'package:flutter/material.dart';
import 'package:hi_common/hi_common.dart';
import 'package:provider/provider.dart';
import 'package:router/annotation.dart';

import 'widget/store_row.dart';

@RouterConfig(LoginSelectStorePage.pageName)
class LoginSelectStorePage extends StatefulWidget {
  static const pageName = '/loginSelectStorePage';

  @override
  _LoginSelectStorePageState createState() => _LoginSelectStorePageState();
}

class _LoginSelectStorePageState extends State<LoginSelectStorePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CenterTitleAppBar(
        title: '',
      ),
      body: Column(
        children: <Widget>[
          LRFTitle(
            '选择店铺',
          ),
          Expanded(
            child: Consumer<LoginUserProvider>(
              builder: (context, loginUserProvider, child) {
                return ListView.separated(
                  padding: EdgeInsets.all(
                    70.w,
                  ),
                  itemBuilder: (context, index) {
                    var current = loginUserProvider.stores[index];
                    var isSelected = loginUserProvider.selectedStore == current;

                    return StoreRow(
                      store: current,
                      isSelected: isSelected,
                      onTap: () {
                        loginUserProvider.setSelectedStore(current);
                      },
                    );
                  },
                  separatorBuilder: (context, index) {
                    return CustomDivider();
                  },
                  itemCount: loginUserProvider.stores.length,
                );
              },
            ),
          ),
          FixedBottomBtn(
            title: '进 入',
            onTap: () {
              var loginUserProvider = Provider.of<LoginUserProvider>(
                context,
                listen: false,
              );
              loginUserProvider.setUserAnd2Home(context);
            },
          ),
        ],
      ),
    );
  }
}
